package com.bige.mall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bige.common.annotation.Log;
import com.bige.common.core.controller.BaseController;
import com.bige.common.core.domain.AjaxResult;
import com.bige.common.enums.BusinessType;
import com.bige.mall.domain.MallOrderItem;
import com.bige.mall.service.IMallOrderItemService;
import com.bige.common.utils.poi.ExcelUtil;
import com.bige.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 订单子单Controller
 * 
 * @author bige
 * @date 2022-01-23
 */
@Api(tags = "订单子单信息管理")
@RestController
@RequestMapping("/mall/orderItem")
public class MallOrderItemController extends BaseController
{
    @Autowired
    private IMallOrderItemService mallOrderItemService;

    /**
     * 查询订单子单列表
     */
    @ApiOperation("查询订单子单列表")
    @PreAuthorize("@ss.hasPermi('mall:orderItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallOrderItem mallOrderItem)
    {
        startPage();
        List<MallOrderItem> list = mallOrderItemService.selectMallOrderItemList(mallOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单子单列表
     */
    @ApiOperation("导出订单子单列表")
    @PreAuthorize("@ss.hasPermi('mall:orderItem:export')")
    @Log(title = "订单子单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallOrderItem mallOrderItem)
    {
        List<MallOrderItem> list = mallOrderItemService.selectMallOrderItemList(mallOrderItem);
        ExcelUtil<MallOrderItem> util = new ExcelUtil<MallOrderItem>(MallOrderItem.class);
        util.exportExcel(response, list, "订单子单数据");
    }

    /**
     * 获取订单子单详细信息
     */
    @ApiOperation("获取订单子单详细信息")
    @PreAuthorize("@ss.hasPermi('mall:orderItem:query')")
    @GetMapping(value = "/{orderItemId}")
    public AjaxResult getInfo(@PathVariable("orderItemId") Long orderItemId)
    {
        return AjaxResult.success(mallOrderItemService.selectMallOrderItemByOrderItemId(orderItemId));
    }

    /**
     * 新增订单子单
     */
    @ApiOperation("新增订单子单")
    @PreAuthorize("@ss.hasPermi('mall:orderItem:add')")
    @Log(title = "订单子单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallOrderItem mallOrderItem)
    {
        return toAjax(mallOrderItemService.insertMallOrderItem(mallOrderItem));
    }

    /**
     * 修改订单子单
     */
    @ApiOperation("修改订单子单")
    @PreAuthorize("@ss.hasPermi('mall:orderItem:edit')")
    @Log(title = "订单子单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallOrderItem mallOrderItem)
    {
        return toAjax(mallOrderItemService.updateMallOrderItem(mallOrderItem));
    }

    /**
     * 删除订单子单
     */
    @ApiOperation("删除订单子单")
    @PreAuthorize("@ss.hasPermi('mall:orderItem:remove')")
    @Log(title = "订单子单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderItemIds}")
    public AjaxResult remove(@PathVariable Long[] orderItemIds)
    {
        return toAjax(mallOrderItemService.deleteMallOrderItemByOrderItemIds(orderItemIds));
    }
}
